#ifndef PLAINRESULTSTREAMWRITTERBOX_H_JM_20130221
#define PLAINRESULTSTREAMWRITTERBOX_H_JM_20130221

// ## jm4bbx
#include "StreamWriterBox.h"
// ## jmlib
#include <jmlib/cast.h>

namespace jm4bbx {

	template<typename T>
	class  PlainResultStreamWritterBox : public StreamWriterBox  {
	public:
		PlainResultStreamWritterBox(const BoxParamPack& pack) 
			: StreamWriterBox(pack) { }

		virtual ~PlainResultStreamWritterBox() {}
		virtual void syncMachEtwas() override {
			GroupPtr g = getGroupPtr(INPUT_GROUP);
			if (g->isPoisoned() || areSignalsInPoisoned()) {
				getOutputStream().close();
				//sendSignalsOut(true);
				wait4Receive();
				return;
			}
			for (; g->getReadPosition() < g->getReadEnd(); 
				g->moveReadPosition()) {
					T value = get_data<T>(INPUT_COLUMN)[g->getReadPosition()];

					std::stringstream stream;

					stream << jmlib::convert<std::string>(value.getIndex())
						<< " -> "
						<<  jmlib::convert<std::string>(value.getKey())
						<< "\n";

					getOutputStream() << stream.str();
			}
			//	
			wait4Receive();
		}
	};

} // namespace jm4bbx


#endif
